package com.supercube.sport.yoga.service.impl;

import com.supercube.sport.yoga.bo.CourseFormsBo;
import com.supercube.sport.yoga.bo.GoodsStockBo;
import com.supercube.sport.yoga.bo.PerformanceDetailsBo;
import com.supercube.sport.yoga.bo.ReportFormsBo;
import com.supercube.sport.yoga.dao.GoodsStockMapper;
import com.supercube.sport.yoga.dao.ReportFormsMapper;
import com.supercube.sport.yoga.reportForms.CourseFormsDTO;
import com.supercube.sport.yoga.reportForms.DailyForms;
import com.supercube.sport.yoga.service.ReportFormsService;
import com.supercube.sport.yoga.vo.GoodsStockVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

/**
 * Description：
 * Created By guowen
 */
@Slf4j
@Service
public class ReportFormsServiceImpl implements ReportFormsService {
    @Autowired
    private ReportFormsMapper reportFormsMapper;

    @Autowired
    private GoodsStockMapper goodsStockMapper;

    @Override
    public List<DailyForms>  getDailyReportList(ReportFormsBo bo){
        return reportFormsMapper.getDailyReportList(bo);
    }
    @Override
    public List<PerformanceDetailsBo> getPerformanceDetailsReportList(String days,String venueId){
        return reportFormsMapper.getPerformanceDetailsReportList(days,venueId);
    }
    @Override
    public List<PerformanceDetailsBo> getCollectionDetailsReportList(String days,String venueId){
        return reportFormsMapper.getCollectionDetailsReportList(days,venueId);
    }

    @Override
    public List<GoodsStockVo> getGoodsStockReportList(GoodsStockBo bo){
        return goodsStockMapper.getGoodsStockReportList(bo);
    }
    @Override
    public List<CourseFormsDTO> getCourseReportList(CourseFormsBo bo){
        List<CourseFormsDTO> list = reportFormsMapper.getCourseReportList(bo);
        // 查询 有卡且卡有效 -->  有效会员
        if(list.size()>0){
            int menberCount = reportFormsMapper.queryMenberNum();
            BigDecimal reservationNum = new BigDecimal("0");
            BigDecimal signNum = new BigDecimal("0");
            BigDecimal cancelSignNum = new BigDecimal("0");
            BigDecimal surplusNum = new BigDecimal("0");
            BigDecimal coursePrice = new BigDecimal("0");
            BigDecimal reservationRate = new BigDecimal("0");
            BigDecimal signRate = new BigDecimal("0");
            for (CourseFormsDTO dto : list) {
                int reNum = Integer.parseInt(dto.getReservationNum());
                if (menberCount == 0 || reNum == 0) {
                    dto.setReservationRate("0.00");
                } else {
                    DecimalFormat df = new DecimalFormat("#.00");
                    dto.setReservationRate(df.format(reNum / menberCount));
                }
                reservationNum = reservationNum.add(new BigDecimal(dto.getReservationNum()));
                signNum = signNum.add(new BigDecimal(dto.getSignNum()));
                cancelSignNum = cancelSignNum.add(new BigDecimal(dto.getCancelSignNum()));
                surplusNum = surplusNum.add(new BigDecimal(dto.getSurplusNum()));
                reservationNum = reservationNum.add(new BigDecimal(dto.getReservationNum()));
                coursePrice = coursePrice.add(new BigDecimal(dto.getCoursePrice()));
                reservationRate = reservationRate.add(new BigDecimal(dto.getReservationRate()));
                signRate = signRate.add(new BigDecimal(dto.getSignRate()));

                dto.setReservationRate(dto.getReservationRate()+"");
                dto.setSignRate(dto.getSignRate()+"");
            }
            CourseFormsDTO all = new CourseFormsDTO();
            all.setDate("合计");
            all.setCourseName("共"+list.size()+"节课");
            all.setReservationNum(reservationNum+"");
            all.setSignNum(signNum+"");
            all.setCancelSignNum(cancelSignNum+"");
            all.setSurplusNum(surplusNum+"");
            all.setCoursePrice(coursePrice+"");
            all.setReservationRate(reservationRate+"");
            all.setSignRate(signRate+"");
            list.add(all);

        }
        return list;
    }
}
